$(function () {
    $('.show-time').click(function(){
        var id= $(this).attr('data-value');
        showTime(id);
    });
    $('.choose-time').click(function(){
    	var id= $(this).attr('data-value');
        chooseTime(id);
    });
    $('.reply-reject').click(function(){
    	var id= $(this).attr('data-value');
        replyReject(id);
    });
    $('.need-comment').click(function(){
    	var id= $(this).attr('data-value');
        needComment(id);
    });
    $(".need-comment-star li").on("click",function(){
        $(this).addClass("pfxtCur");
        $(this).prevAll().addClass("pfxtCur");
        $(this).nextAll().removeClass("pfxtCur");
    });
    $(".need-comment-star li").dblclick(function(){
        $(".need-comment-star li").removeClass("pfxtCur");
    });
    $(document).on('click','.submit_comment', function () {
        var invite_id =$(this).attr('data-invite_id');
        var commentstar = $('#need-comment-'+invite_id).find(".need-comment-star");
        var hjpj = commentstar.find(".pfxtCur:last").text();
        var content = $('#need-comment-'+invite_id).find(".need-comment-text").val();

        var company_id = $(this).attr('data-company_id');

        var params = {
            url: '/member/need/comments',
            type: 'POST',
            dataType: 'json',
            data:'vid='+invite_id+'&cid='+company_id+'&content='+content+'&commentstar='+hjpj,
        };
        $.ajax(params).done(function(resp){
            if(resp.status == 'true') {
                var data = resp.data;

                var li_html = '';
                for(var i=1;i<6;i++){
                    if(i<=data.commentstar){
                        li_html += '<li class="pfxtCur">' +i+'</li>';
                    }else{
                        li_html +='<li>'+i+'</li>'
                    }
                }
                $('#need-comment-'+invite_id).find('.need-comment-star').html(li_html);
                var content_html = '<span class="c85 fl">面试过程：</span>';
                content_html += data.content;
                content_html += '<div class="clr"></div>';
                $('#need-comment-'+invite_id).find('.need-comment-content').html(content_html);
                $('#need-comment-'+invite_id).find('.need-comment-btn').remove();
                layer.closeAll();
                layer.open({title:'系统提示',content:resp.msg});
            }else{
                layer.open({title:'系统提示',content:resp.msg});
            }
        }).fail(function(erro){
            layer.open({title:'系统提示',content:'网络异常...'});
        });

    });
    $(document).on('click','.close_comment', function () {
        layer.closeAll();
    });
    $(document).on('click','.need-btn-cancel', function () {
        layer.closeAll();
    });
    
    $(document).on('click','.delete-need',function(){
    	var nid = $(this).attr('data-value');
    	var text = $(this).attr('data-text');
    	layer.confirm('确定要删除［'+text+'］需求吗', {
    		  btn: ['确定','取消'] //按钮
    		}, function(){
    			var params = {
    					url: '/member/need/destroy/'+nid,
    					type: 'DELETE',
    					dataType: 'json',
    					data: {},
    			};
    			$.ajax(params).done(function(resp){
    				if(resp.status == 'success') {
    					$('#need_'+nid).remove();
    					layer.open({title:'提示',content:resp.msg});
    				}else if(resp.status == 'fuck'){
    					layer.open({
    						type: 1,
    				        title: ['确认删除', 'font-size:18px;padding-left:170px;'],
    				        btn: ['强制删除','取消'],
    				        skin: 'layui-layer-demo', //样式类名
    				        closeBtn: 1,
    				        shift: 2,
    				        shadeClose: true, //开启遮罩关闭
    				        area: ['450px', '340px'], //宽高
    				        content: "<div style='width:100%;height:100%;text-align:center;line-height:240px;font-size:18px;'>"+resp.msg+"</div>",
    				        yes:function(){
    				        	params.data = {fuck:'fuck'};
    				        	$.ajax(params).done(function(data){
    				        		if(data.status == 'success') {
    				        			layer.closeAll();
    				        			$('#need_'+nid).remove();
    			    					layer.msg(data.msg);
    				        		}else{
    				        			layer.closeAll();
    				        			layer.msg(data.msg);
    				        		}
    				        	});
    				        },
    				        btn2: function () {
    				        	layer.closeAll();
    				        }
    					});
    				}else{
    					layer.open({title:'提示',content:resp.msg});
    				}
    			}).fail(function(erro){
    				error(erro);
    			});
    		}, function(){
    		  
    		});
    });

});
function error(erro){
	var response = eval('(' + erro.responseText + ')');
	var errors = '';
    $.each(response,function(k,v){
        errors +="<div>"+v+"</div>";
    })
    layer.open({
        title: '系统提示',
        content: errors
    });
}
function showTime(id){
    layer.open({
        type: 1,
        title: [''],
        skin: 'layui-layer-demo', //样式类名
        closeBtn: 1,
        shift: 2,
        shadeClose: true, //开启遮罩关闭
        area: ['450px', '340px'], //宽高
        content: $('#show-time-'+id)
    });
}
function chooseTime(id){
    layer.open({
        type: 1,
        title: ['面试时间', 'font-size:18px;padding-left:170px;'],
        btn: ['确认面试','拒绝邀请'],
        skin: 'layui-layer-demo', //样式类名
        closeBtn: 1,
        shift: 2,
        shadeClose: true, //开启遮罩关闭
        area: ['450px', '340px'], //宽高
        content: $('#choose-time-'+id),
        yes:function(){
			var interview = $('#choose-time-'+id).find('input[name=interview_at]:checked').val();
            console.log(interview);
			var params = {
					url: '/member/resume/deal',
					type: 'POST',
					dataType: 'json',
					data: {interview_at:interview,id:id},
			};
			$.ajax(params).done(function(resp){
				if(resp.status = 'success'){
					layer.closeAll();
					layer.open({title:'提示',content:resp.msg,yes:function(){
						window.location.reload();
					}});
				} else{
					layer.open({title:'提示',content:resp.msg});
				}
			}).fail(function(erro){
				layer.msg('网络异常...');
			});
        },
        btn2: function () {
        	replyReject(id);
        }
    });
}

function replyReject(id){
    layer.open({
        type: 1,
        title:[''],
        btn: ['确认拒绝', '稍加考虑'],
        skin: 'layui-layer-demo', //样式类名
        closeBtn: 1,
        shift: 2,
        shadeClose: true, //开启遮罩关闭
        area: ['450px', '340px'], //宽高
        content: $('#reply-reject-'+id),
        yes: function () {
        	var params = {
					url: '/member/resume/reject/'+id,
					type: 'POST',
					dataType: 'json',
					data: {},
			};
            $.ajax(params).done(function(resp){
            	layer.closeAll();
            	layer.open({title:'提示',content:resp.msg})
            }).fail(function(erro){
            	layer.msg('网络异常...');
            });
        },
        btn2: function () {
            layer.closeAll();
        }
    });
}
function needComment(id){
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        shift: 2,
        shadeClose: true,
        area: ['550px', '440px'], //宽高
        content: $('#need-comment-'+id)
    });
}